Dart BigInt operator unary-
Syntax & Examples
BigInt.operator unary- operator
The `unary-` operator returns the negative value of this BigInt.
Syntax of BigInt.operator unary-
The syntax of BigInt.operator unary- operator is:
operator unary-() → BigIntThis operator unary- operator of BigInt return the negative value of this integer.
✐ Examples
1 Get negative value of positive BigInt
In this example,
- We define a positive BigInt
numwith a value of10. - We use the `unary-` operator to get the negative value of
num. - We print the negative value to standard output.
Dart Program
void main() {
BigInt num = BigInt.from(10);
BigInt negative = -num;
print('Negative value: $negative');
}Output
Negative value: -10
2 Get negative value of negative BigInt
In this example,
- We define a negative BigInt
numwith a value of-10. - We use the `unary-` operator to get the negative value of
num. - We print the negative value to standard output.
Dart Program
void main() {
BigInt num = BigInt.from(-10);
BigInt negative = -num;
print('Negative value: $negative');
}Output
Negative value: 10
Summary
In this Dart tutorial, we learned about operator unary- operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.